package sortAlgorithm;

import java.util.Arrays;

/**
 * @author： pang-yun
 * @date： 2021-09-24 15:38
 * 功能目的 ：用于
 */

public class ShellSortDemo {
    public static void main(String[] args) {
        int[] arr = new int[]{8, 7, 6, 5, 4, 3, 2, 1, 10, 23, 34, 456};
        shellSortMove(arr);
    }

    public static void shellSortMove(int[] arr) {
        int insertVal = 0;
        int insertIndex = 0;
        for (int step = arr.length / 2; step > 0; step /= 2) {
            for (int i = step; i < arr.length; i++) {
                insertVal=arr[i];
                insertIndex=i-step;
                while (insertIndex>=0 && insertVal<arr[insertIndex]){
                    arr[insertIndex+step]=arr[insertIndex];
                    insertIndex-=step;
                }
                arr[insertIndex+step]=insertVal;
            }
            System.out.println(Arrays.toString(arr));
        }
    }
}
